home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat12 / mdwi / mdwi.c next >
Encoding:
C/C++ Source or Header  |  1978-01-17  |  3.3 KB  |  167 lines

  1. /*
  2.  
  3.     MDWI
  4.     MakeDir With Icon
  5.     Septembre 1992
  6.  
  7.     © 1992 PERRINE bertrand, All Rights Reserved.
  8.  
  9.     NB : you must have OS 2.0 to use MDWI
  10.  
  11. */
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <clib/icon_protos.h>
  16. #include <pragmas/exec_pragmas.h>
  17. #include <pragmas/dos_pragmas.h>
  18. #include <pragmas/icon_pragmas.h>
  19. #include <stdlib.h>
  20.  
  21. /* prototypes des fonctions */
  22.  
  23. void FaireIcone(void);
  24. void ErrIcone(void);
  25.  
  26. int CXBRK(void)            { return(0); }            /* CTRL-C lattice inhibé */
  27. void chkabort(void)    { return; }
  28.  
  29. /* Bibliothéques */
  30.  
  31. extern struct Library *SysBase;                    /* Bibliothèques ouvertes par le compilateur */
  32. extern struct Library *DOSBase;
  33.  
  34. struct                 Library    *IconBase = NULL;
  35.  
  36. /* numéro de version */
  37.  
  38. UBYTE ver[]="\0$VER: MakeDirWithIcon 1.0 (23.9.92)\0";
  39.  
  40. /* variables globales */
  41.  
  42. struct RDArgs *argclilu = NULL; 
  43.  
  44. UBYTE compte = 0;                                                /* nombre d'arguments */
  45. UBYTE **repertoires;                                        /* Array retournée par RDargs */
  46.  
  47. /*****************
  48.  
  49.     Et voici El Code
  50.  
  51. *****************/
  52.  
  53.  
  54. void main(void)
  55. {
  56.  
  57. LONG args[2];
  58. LONG erreur;
  59. LONG status = 0;
  60. BPTR lelock;
  61.  
  62.     args[0] = NULL;                                                                        /* Initialisation des arguments */
  63.     args[1] = NULL;
  64.  
  65.     argclilu = ReadArgs("NAME/M,ICON/S", args, NULL); /* Merci le Dos qui fait le boulot tout seul */
  66.  
  67.     if (argclilu)                                                                            /* test si RDArgs à été fourni */
  68.     {
  69.         if (args[0])                                                                        /* test l'existence d'arguments */
  70.         {
  71.             repertoires =(UBYTE **)args[0];
  72.  
  73.             while (repertoires[compte])                                        /* tant qu'il y a des arguments */
  74.             {
  75.  
  76.                 lelock = Lock(repertoires[compte], ACCESS_READ);
  77.  
  78.                 if (lelock)                                                                    /* le repertoire existant ? */
  79.                 {
  80.                     VPrintf( "%s already exists\n", (LONG *)&repertoires[compte]);
  81.                     status = 10;
  82.                 }
  83.                 else
  84.                 {
  85.                     lelock = CreateDir(repertoires[compte]);
  86.  
  87.                     if(!lelock)                                                                /* création OK ? */
  88.                     {
  89.                         VPrintf( "Can't create directory %s\n", (LONG *)&repertoires[compte]);
  90.                         erreur = IoErr();
  91.                         PrintFault(erreur, NULL);
  92.                         status = 10;
  93.                     }
  94.                     else
  95.                         if (args[1])                                                        /* création icones ? */
  96.                             FaireIcone();
  97.                 }
  98.                 UnLock(lelock);
  99.                 compte++;                                                                        /* argumemt suivant */
  100.             }
  101.         }
  102.         else
  103.         {
  104.             VPrintf( "No name given\n", NULL);
  105.             status = 20;
  106.         }
  107.         FreeArgs(argclilu);                                                            /* libération de RDArgs */
  108.     }
  109.     else
  110.     {
  111.         erreur = IoErr();
  112.         PrintFault(erreur, NULL);
  113.         status = 20;
  114.     }
  115.  
  116.     exit(status);                                                                            /* on s'en va */
  117. }
  118.  
  119.  
  120. /********************************
  121.  
  122.     FaireIcone : comme son nom l'indique
  123.  
  124. ********************************/
  125.  
  126. void FaireIcone()
  127. {
  128.  
  129. struct DiskObject *objeticone;
  130.  
  131.     IconBase = (struct Library *)OpenLibrary("icon.library",37L);
  132.     if(IconBase)
  133.     {
  134.         objeticone = GetDefDiskObject(WBDRAWER);            /* Obtention de l'icone par defaut du */
  135.         if (objeticone)
  136.         {
  137.             if (!PutDiskObject(repertoires[compte], objeticone)) /*création de l'icone */
  138.                 ErrIcone();
  139.  
  140.             FreeDiskObject(objeticone);
  141.         }
  142.         else
  143.             ErrIcone();
  144.  
  145.         CloseLibrary(IconBase);        
  146.     }
  147.     else
  148.         VPrintf("Can't create icon for %s\n Unable to open icon.library\n",(LONG *)&repertoires[compte]);
  149.  
  150. }
  151.  
  152. /********************************
  153.  
  154.     ErrIcone : Affichage de l'erreur produite lors de la création de l'icone
  155.  
  156. ********************************/
  157.  
  158. void ErrIcone()
  159. {
  160.  
  161. LONG erricone;
  162.  
  163.     erricone = IoErr();
  164.     VPrintf("Can't create icon for %s\n",(LONG *)&repertoires[compte]);
  165.     PrintFault(erricone, NULL);
  166.  
  167. }